<?php

namespace App\Admin\Actions\Info;

use App\Miya\Models\Classify;
use Encore\Admin\Actions\BatchAction;
use Illuminate\Database\Eloquent\Collection;

class SelectClassify extends BatchAction
{
    public $name = '转移分类';

    public function handle(Collection $collection)
    {
        foreach ($collection as $model) {
            $model->classify_id = request()->get('classify_id');
            $model->save();
        }

        return $this->response()->success('信息转移成功!')->refresh();
    }

    public function form()
    {
        $classifies = Classify::selectOptions(function ($query) {
            return $query->where('module_id', request()->route('module'));
        });

        unset($classifies[0]);

        $this->select('classify_id', '分类')->options($classifies);
    }

}
